package com.jinly.ryder.ansible.service.model;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;

@Data
public class AnsiblePingResult {

    private boolean success;
    private String host;
    private String msg;

    public AnsiblePingResult(String text) {
        String[] splits = text.split("=>");
        if (splits[0].contains("\n")) {
            splits[0] = splits[0].split("\n")[1];
        }
        String[] ss = splits[0].split("\\|");
        this.host = ss[0].trim();
        this.success = "SUCCESS".equals(ss[1].trim());
        if (!success) {
            JSONObject jsonObject = JSONObject.parseObject(splits[1].trim());
            this.msg = jsonObject.getString("msg");
        }
    }
}
